package com.jet.member.controller;

import com.jet.core.result.ResultJson;
import com.jet.member.domain.dto.MemberTagDto;
import com.jet.member.domain.entity.MemberTag;
import com.jet.member.service.IMemberTagService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/member/tag")
public class MemberTagController {

    private final IMemberTagService memberTagService;

    public MemberTagController(IMemberTagService memberTagService) {
        this.memberTagService = memberTagService;
    }

    @PostMapping
    public ResultJson<MemberTag> create(@RequestHeader long merchantNo,
                                        @RequestHeader long storeNo,
                                        @RequestHeader String accountId,
                                        @Validated @RequestBody MemberTagDto dto) {
        MemberTag entity = memberTagService.create(merchantNo, dto);
        return ResultJson.ok(entity);
    }

    @PutMapping("/{id}")
    public ResultJson<Void> edit(@RequestHeader long merchantNo,
                                 @RequestHeader long storeNo,
                                 @RequestHeader String accountId,
                                 @PathVariable("id") String id,
                                 @Validated @RequestBody MemberTagDto dto) {
        memberTagService.edit(merchantNo, id, dto);
        return ResultJson.ok();
    }

    @DeleteMapping("/{id}")
    public ResultJson<Void> delete(@RequestHeader long merchantNo,
                                   @RequestHeader long storeNo,
                                   @RequestHeader String accountId,
                                   @PathVariable("id") String id) {
        memberTagService.removeById(id);
        return ResultJson.ok();
    }
}
